<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'PlanItemList',
  mixins: [JeecgListMixin],
  props: {
    mainId: {
      type: String,
      default: '',
      required: false
    }
  },
  watch: {
    mainId: {
      immediate: true,
      handler(val) {
        if (!this.mainId) {
          this.clearList()
        } else {
          this.queryParam['id'] = val
          this.loadData(1, () => {
            if (this.dataSource && this.dataSource.length > 0) {
              this.dataSource.forEach((item, index) => {
                item.rowKey = index
              })
            }
          })
        }
      }
    }
  },
  data() {
    return {
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '订单编号',
          align: 'center',
          dataIndex: 'orderCode'
        },
        {
          title: '物料编码',
          align: 'center',
          dataIndex: 'productCode'
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'productBatchNo'
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'materialSpec'
        },
        {
          title: '配方号',
          align: 'center',
          dataIndex: 'formulaNumber'
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'meUnit_dictText'
        },
      ],
      url: {
        list: '/pro/tslProWorkshopPlan/queryTslProWorkshopPlanInfoByMainId'
      },
      disableMixinCreated: true
    }
  },
  methods: {
    clearList() {
      this.dataSource = []
      this.selectedRowKeys = []
      this.ipagination.current = 1
    }
  }
}
</script>

<template>
  <div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="rowKey"
      :scroll="{x:true}"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange">
    </a-table>
  </div>
</template>

<style scoped>

</style>